package com.sjy.project.fym.apply.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sjy.framework.aspectj.lang.annotation.Log;
import com.sjy.framework.aspectj.lang.enums.BusinessType;
import com.sjy.project.fym.apply.domain.FyGoodsApplyHis;
import com.sjy.project.fym.apply.service.IFyGoodsApplyHisService;
import com.sjy.framework.web.controller.BaseController;
import com.sjy.framework.web.domain.AjaxResult;
import com.sjy.common.utils.poi.ExcelUtil;
import com.sjy.framework.web.page.TableDataInfo;

/**
 * 审批记录Controller
 * 
 * @author ljb
 * @date 2022-05-04
 */
@Controller
@RequestMapping("/fym/apply/his")
public class FyGoodsApplyHisController extends BaseController
{
    private String prefix = "fym/apply";

    @Autowired
    private IFyGoodsApplyHisService fyGoodsApplyHisService;

    @RequiresPermissions("fym:apply:view")
    @GetMapping()
    public String apply()
    {
        return prefix + "/apply";
    }

    /**
     * 查询审批记录列表
     */
    @RequiresPermissions("fym:apply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FyGoodsApplyHis fyGoodsApplyHis)
    {
        startPage();
        List<FyGoodsApplyHis> list = fyGoodsApplyHisService.selectFyGoodsApplyHisList(fyGoodsApplyHis);
        return getDataTable(list);
    }

    /**
     * 导出审批记录列表
     */
    @RequiresPermissions("fym:apply:export")
    @Log(title = "审批记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FyGoodsApplyHis fyGoodsApplyHis)
    {
        List<FyGoodsApplyHis> list = fyGoodsApplyHisService.selectFyGoodsApplyHisList(fyGoodsApplyHis);
        ExcelUtil<FyGoodsApplyHis> util = new ExcelUtil<FyGoodsApplyHis>(FyGoodsApplyHis.class);
        return util.exportExcel(list, "审批记录数据");
    }

    /**
     * 新增审批记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存审批记录
     */
    @RequiresPermissions("fym:apply:add")
    @Log(title = "审批记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FyGoodsApplyHis fyGoodsApplyHis)
    {
        return toAjax(fyGoodsApplyHisService.insertFyGoodsApplyHis(fyGoodsApplyHis));
    }

    /**
     * 修改审批记录
     */
    @RequiresPermissions("fym:apply:edit")
    @GetMapping("/edit/{hisId}")
    public String edit(@PathVariable("hisId") Long hisId, ModelMap mmap)
    {
        FyGoodsApplyHis fyGoodsApplyHis = fyGoodsApplyHisService.selectFyGoodsApplyHisByHisId(hisId);
        mmap.put("fyGoodsApplyHis", fyGoodsApplyHis);
        return prefix + "/edit";
    }

    /**
     * 修改保存审批记录
     */
    @RequiresPermissions("fym:apply:edit")
    @Log(title = "审批记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FyGoodsApplyHis fyGoodsApplyHis)
    {
        return toAjax(fyGoodsApplyHisService.updateFyGoodsApplyHis(fyGoodsApplyHis));
    }

    /**
     * 删除审批记录
     */
    @RequiresPermissions("fym:apply:remove")
    @Log(title = "审批记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fyGoodsApplyHisService.deleteFyGoodsApplyHisByHisIds(ids));
    }
}
